package com.spsy.order.mq.listener;

import com.alibaba.fastjson2.JSON;
import com.spsy.order.domain.Order;
import com.spsy.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 延迟队列消费者
 */
@Slf4j
@Component
public class DelayQueueConsumer {

    @Autowired
    private IOrderService orderService;


    @RabbitListener(queues = "lzp_delayed_queue2206a")
    private void receiveDelayQueue(Message message) {
        String orderId = new String(message.getBody());
        //通过msg=订单号id
        //修改数据库的数据
        Order order = this.orderService.selectOrderByOrderId(Long.valueOf(orderId));
        if(order.getOrderStatus().equals("1")){
            order.setOrderStatus("4");
            int updateCount = this.orderService.updateOrder(order);
            log.info("updateCount:{}", updateCount);
        }else {
            log.info("订单状态已经不是未支付了，order:{}", JSON.toJSONString(order));
        }

        log.info("=====>2206a 收到延迟消息----当前时间{}，收到延迟队列的消息{}", new Date(), orderId);
    }
}